package com.eclink.asset.portal.controller;


import com.eclink.asset.domain.dto.DistributeItem;
import com.eclink.asset.portal.domain.dto.PortalSettingDTO;
import com.eclink.asset.portal.domain.dto.PortalSettingSaveDTO;
import com.eclink.asset.portal.service.DataBoardService;
import com.eclink.asset.service.AssetCategoryService;
import com.eclink.asset.sys.domain.dto.UserFavoritesMenuDTO;
import com.eclink.asset.sys.service.SysMenuServiceImpl;
import com.eclink.asset.warehouse.service.WarehouseService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysMenu;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.domain.dto.query.RecordMenuQueryDTO;
import com.ruoyi.domain.entity.RecordMenuVisit;
import com.ruoyi.web.service.IndexService;
import com.ruoyi.web.service.RecordMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.List;

/**
 * 首页的相关接口
 *
 * @author chenshixian
 */
@Api(tags="门户配置接口")
@RestController
@RequestMapping("portalSetting")
public class PortalSettingController {

    @Resource
    private SysMenuServiceImpl sysMenuService;

    @Resource
    private DataBoardService dataBoardService;

    @GetMapping("myFavoritesMenu")
    public ResponseEntity<List<UserFavoritesMenuDTO>> myFavoritesMenu() {
        return ResponseEntity.ok(sysMenuService.selectMyFavoritesMenuForCheck());
    }

    @PutMapping("save")
    public ResponseEntity<Integer> save(@RequestBody PortalSettingSaveDTO saveDTO) {
        sysMenuService.saveMyFavoritesMenu(saveDTO.getFavoritesMenu());
        dataBoardService.saveMyDataBoard(saveDTO.getDataBoard());
        return ResponseEntity.ok(1);
    }

    @PutMapping("resetMyFavoritesMenu")
    public ResponseEntity<List<SysMenu>> resetMyFavoritesMenu() {
        List<SysMenu> commonMenuList = sysMenuService.resetMyFavoritesMenu();
        return ResponseEntity.ok(commonMenuList);
    }


    /**
     * 获取当前用户首页的配置
     * @return
     */
    @GetMapping("getMyPortalSetting")
    public ResponseEntity<PortalSettingDTO> getMyPortalSetting() {
        PortalSettingDTO res = new PortalSettingDTO();
        // 常用菜单
        res.setFavoritesMenuList(sysMenuService.selectMyFavoritesMenu());
        // 数据看板
        res.setDataBoardGroupList(dataBoardService.selectMyDataBoardGroup(1));
        // 图表看板
        res.setDataBoardGroupListDiagram(dataBoardService.selectMyDataBoardGroup(2));
        return ResponseEntity.ok(res);
    }


}
